//
//  PostViewController.swift
//  Post
//
//  Created by 郑东喜 on 2016/11/10.
//  Copyright © 2016年 郑东喜. All rights reserved.
//  测试请求页面

import UIKit

class PostViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
//        //(1）设置请求路径
//        let url:NSURL = NSURL(string:addressUrl)!//不需要传递参数
//        
//        //(2) 创建请求对象
//        let request:NSMutableURLRequest = NSMutableURLRequest(url: url as URL) //默认为get请求
//        request.timeoutInterval = 5.0 //设置请求超时为5秒
//        request.httpMethod = "POST"  //设置请求方法
//
//        let token = localSave.object(forKey: userToken) as! String
//        
//        print(token)
//        //设置请求体
//
//        let param:NSString = NSString(format:"token=%@&ac=%@",token,"list")
//        
//        //把拼接后的字符串转换为data，设置请求体
//        request.httpBody = param.data(using: String.Encoding.utf8.rawValue)
//        
//        //(3) 发送请求
//        NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue:OperationQueue()) { (res, data, error)in
//            //返回主线程执行
//            DispatchQueue.main.sync {
//                do
//                {
//                    let dic = try JSONSerialization.jsonObject(with: data! as Data, options: JSONSerialization.ReadingOptions.allowFragments) as! NSDictionary
//                    print(dic)
//                } catch {
//                    
//                }
//                
//                print(res!)
//            }
//        }
        if localSave.object(forKey: userToken) as? String != nil {
            let token = localSave.object(forKey: userToken) as! String
            
            let param = ["token":token,
                         "ac":"list"]
            
            postWithPath(path: addressUrl, paras: param, success: { (data) in
                print(data)
                
                
            }) { (error) in
                print(error.localizedDescription)
            }


        } else {
            MBManager.showBriefAlert("登陆后才可查看收获信息")
            return
        }
        
    }
}



